home *** CD-ROM | disk | FTP | other *** search
- /*
-
- Name:
- MIKMOD.C
-
- Description:
- Modplaying example of mikmod.
-
- MSDOS: BC(y) Watcom(y) DJGPP(y)
- Win95: BC(y*)
- Os2: y
- Linux: n
-
- * console mode only
- (y) - yes
- (n) - no (not possible or not useful)
- (?) - may be possible, but not tested
-
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <SIOUX.h>
-
- #include "mikmod.h"
-
- void tickhandler(void)
- {
- MP_HandleTick(); /* play 1 tick of the module */
- MD_SetBPM(mp_bpm);
- }
-
- static short isPressed(unsigned short k)
- {
- unsigned char km[16];
-
- GetKeys((unsigned long*) km);
- return ((km[k>>3] >> (k & 7)) & 1);
- }
-
- static Boolean CmdPeriod(void)
- {
- if (isPressed(0x37) && isPressed(0x0C))
- {
- FlushEvents(keyDownMask + mDownMask, 0);
- return TRUE;
- }
- return FALSE;
- }
-
- static void pstrcat(StringPtr dst, StringPtr src)
- /*
- * pstrcat - add string 'src' to end of string 'dst'
- */
- {
- /* copy string in */
- BlockMove(src + 1, dst + *dst + 1, *src);
- /* adjust length byte */
- *dst += *src;
- }
-
- static void pstrinsert(StringPtr dst, StringPtr src)
- /*
- * pstrinsert - insert string 'src' at beginning of string 'dst'
- */
- {
- /* make room for new string */
- BlockMove(dst + 1, dst + *src + 1, *dst);
- /* copy new string in */
- BlockMove(src + 1, dst + 1, *src);
- /* adjust length byte */
- *dst += *src;
- }
-
- static OSErr PathNameFromDirID(long dirID, short vRefNum, StringPtr fullPathName)
- {
- DirInfo block;
- Str255 directoryName;
- OSErr err;
-
- fullPathName[0] = '\0';
-
- block.ioDrParID = dirID;
- block.ioNamePtr = directoryName;
- do {
- block.ioVRefNum = vRefNum;
- block.ioFDirIndex = -1;
- block.ioDrDirID = block.ioDrParID;
- err = PBGetCatInfo((CInfoPBPtr) &block, FALSE);
- if (err != noErr)
- return err;
- pstrcat(directoryName, (StringPtr)"\p:");
- pstrinsert(fullPathName, directoryName);
- } while (block.ioDrDirID != 2);
- return noErr;
- }
-
- static OSErr PathNameFromWD(long vRefNum, StringPtr pathName)
- /*
- * PathNameFromWD:
- * Given an HFS working directory, this routine returns the full pathname that
- * corresponds to it. It does this by calling PBGetWDInfo to get the VRefNum and
- * DirID of the real directory. It then calls PathNameFromDirID, and returns its
- * result.
- */
- {
- WDPBRec myBlock;
- OSErr err;
-
- if (vRefNum == -1)
- PathNameFromDirID(2, -1, pathName);
- else {
- myBlock.ioNamePtr = nil;
- myBlock.ioVRefNum = vRefNum;
- myBlock.ioWDIndex = 0;
- myBlock.ioWDProcID = 0;
- err = PBGetWDInfo(&myBlock, FALSE);
- if (err != noErr)
- return err;
- PathNameFromDirID(myBlock.ioWDDirID, myBlock.ioWDVRefNum, pathName);
- }
- return noErr;
- }
- void main(void)
- {
- EventRecord event;
- UNIMOD *mf;
- int cmderr=0; /* error in commandline flag */
- int morehelp=0; /* set if user wants more help */
- int quit;
- int t;
- Str255 fName;
-
- puts(mikbanner);
-
- /*
- Initialize soundcard parameters.. you _have_ to do this
- before calling MD_Init(), and it's illegal to change them
- after you've called MD_Init()
- */
-
- md_mixfreq =44100; /* standard mixing freq */
- md_dmabufsize =10000; /* standard dma buf size */
- md_mode =DMODE_16BITS|DMODE_STEREO | DMODE_INTERP; /* standard mixing mode */
- md_device =0; /* standard device: autodetect */
-
- /*
- Register the loaders we want to use..
- */
-
- ML_RegisterLoader(&load_m15); /* if you use m15load, register it as first! */
- ML_RegisterLoader(&load_mod);
- ML_RegisterLoader(&load_mtm);
- ML_RegisterLoader(&load_s3m);
- ML_RegisterLoader(&load_stm);
- ML_RegisterLoader(&load_ult);
- ML_RegisterLoader(&load_uni);
- ML_RegisterLoader(&load_xm);
-
- /*
- Register the drivers we want to use:
- */
-
- MD_RegisterDriver(&drv_mac);
- MD_RegisterPlayer(tickhandler);
-
- /* Parse option switches using standard getopt function: */
- /* initialize soundcard */
-
- if(!MD_Init()){
- printf("Driver error: %s.\n",myerr);
- return;
- }
-
- printf("Playing %d bit %s %s sound at %.1f kHz\n\n",
- (md_mode&DMODE_16BITS) ? 16:8,
- (md_mode&DMODE_INTERP) ? "interpolated":"normal",
- (md_mode&DMODE_STEREO) ? "stereo":"mono",
- md_mixfreq / 1000.0);
-
- // [DEMOS] -> Standard open file
- {
- SFReply reply;
- SFTypeList typeList = { '????' };
- Point where = { -1, -1 };
-
- SFGetFile(where, "\pOpen MOD file:", NULL, -1, typeList, NULL, &reply);
- if (!reply.good) {
- return;
- }
- PathNameFromWD(reply.vRefNum, fName);
- pstrcat(fName, reply.fName);
- PtoCstr(fName);
- }
- mf=ML_LoadFN((char*) fName);
- if (mf == NULL)
- {
- printf("Couldn't load mod-file \"%s\"\n\n", fName);
- return;
- }
- /* initialize modplayer to play this module */
-
- MP_Init(mf);
- printf( "Songname : %s\nMOD-Type : %s\n", mf->songname, mf->modtype);
- /*
- set the number of voices to use.. you
- could add extra channels here (e.g. md_numchn=mf->numchn+4; )
- to use for your own soundeffects:
- */
-
- printf("\nCmd-Period to quit.\n");
-
- md_numchn=mf->numchn;
-
- /* start playing the module: */
-
- MD_PlayStart();
-
- // [DEMOS] -> Do anything here, synthesise in real-time @ snd interrupt
- while(!MP_Ready())
- if (WaitNextEvent(everyEvent, &event, -1, NULL))
- SIOUXHandleOneEvent(&event);
-
- MD_PlayStop(); /* stop playing */
- ML_Free(mf); /* and free the module */
-
- MD_Exit();
- }